﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LSEntity
{
    /// <summary>
    /// 题型分类
    /// </summary>
    public enum QuestionCategory
    {
        /// <summary>
        /// 听力
        /// </summary>
        L,
        /// <summary>
        /// 语法
        /// </summary>
        G,
        /// <summary>
        /// 词汇
        /// </summary>
        V,
        /// <summary>
        /// 阅读写作
        /// </summary>
        R,
        /// <summary>
        /// 补充内容
        /// </summary>
        E
    }

    [Serializable]
    public class QuestionType
    {
        #region Properties

        public int Id
        {
            get;
            set;
        }

        public int TypeId
        {
            get;
            set;
        }

        public Curriculum CurriculumId
        {
            get;
            set;
        }

        public string EasyHard
        {
            get;
            set;
        }

        public QuestionCategory Category
        {
            get;
            set;
        }

        public string Description
        {
            get;
            set;
        }

        /// <summary>
        /// 有新题或为空
        /// </summary>
        public bool HadNew
        {
            get;
            set;
        }

        /// <summary>
        /// 该题型下的题目数
        /// </summary>
        public int CountNum
        {
            get
            {
                return QIdList.Count;
            }
        }

        /// <summary>
        /// 该题型下的题目ID序列
        /// 备注：该id列可能还包含该question的受欢迎度；格式为（id|欢迎度,id|欢迎度）
        /// 要得到questionId的List请访问QIdList；
        /// </summary>
        public string QIdsStr
        {
            get;
            set;
        }

        /// <summary>
        /// 该题型下的题目ID列
        /// </summary>
        public List<int> QIdList
        {
            get
            {
                var rData = new List<int>();
                if (!String.IsNullOrEmpty(QIdsStr))
                {
                    var ids = QIdsStr.Split(',');
                    foreach (var id in ids)
                    {
                        var qid = id;
                        if (id.IndexOf("|", StringComparison.Ordinal) > -1)
                        {
                            qid = id.Split('|')[0];
                        }
                        int r;
                        if (int.TryParse(qid, out r))
                            rData.Add(r);
                    }
                }
                return rData;
            }
        }
        #endregion

        #region public function

        public override string ToString()
        {
            return "count=" + CountNum + ",typeId=" + TypeId + ", Id=" + Id + ", category" + Category + ", easyHard" +
                   EasyHard + ", CurriculumId=" + CurriculumId + ", description=" + Description;
        }

        #endregion
    }

    public class QuestionOT
    {
        public List<QuestionType> QuestionTypeList { get; set; }
        public List<List<QuestionForOT>> QuestionForOTList { get; set; }
    }

    [Serializable]
    public class QuestionForOT
    {
        public int ExamId { get; set; }
        public int PaperId { get; set; }
        public int QuestionId { get; set; }
        public float Score { get; set; }
        public short SubQuestionFlag { get; set; }
        public int OrderId; //for star test  题目的序号
        public Question Question { get; set; }
    }

    [Serializable]
    public class Question
    {
        public int QuestionId { get; set; }
        public string SourceId { get; set; }
        public int QuestionTypeId { get; set; }
        public short KnowledgeId { get; set; }
        public int GroupNum { get; set; }
        public Curriculum CurriculumId { get; set; }
        public short GradeId { get; set; }
        public short ModuleId { get; set; }
        public short UnitId { get; set; }
        public short AssignmentId { get; set; }
        public string QuestionNum { get; set; }
        public string Image { get; set; }
        public string Sound { get; set; }
        public string QuestionTitle { get; set; }
        public string Answer { get; set; }
        public string Distracter1 { get; set; }
        public string Distracter2 { get; set; }
        public string Distracter3 { get; set; }
        public string Translation { get; set; }
        public string AudioText { get; set; }
        public short IsNew { get; set; }
        public string LastUpdatedBy { get; set; }
        public DateTime LastUpdateTime { get; set; }
        public int CountResearcher { get; set; }
        public int CountPopular { get; set; }
        public int Difficulty { get; set; }
    }
}
